package com.titaniume.rqbbitmq.two;

import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import java.lang.String;
import com.titaniume.rqbbitmq.util.RabbitMqUtils;

/**
 * @ProjectName: rqbbitmq
 * @Package: com.titaniume.rqbbitmq.two
 * @ClassName: Worker01
 * @Author: huangrenfei
 * @Description: 工作线程 （消费者）
 * @Date: 2021/12/16 15:17
 * @Version: 1.0
 */
public class Worker01 {

    //队列名称
    public static  final String QUEUE_NAME ="test";


    //接收消息
    public static void main(String[] args) throws Exception{

        Channel channel = RabbitMqUtils.getChannel();

        DeliverCallback deliverCallback =(consumerTag,delivery)->{
            String receivedMessage = new String(delivery.getBody());
            System.out.println("接收到消息:"+receivedMessage);
        };

        CancelCallback cancelCallback = consumerTag->{
            System.out.println(consumerTag+"消费者取消消费接口回调逻辑");
        };
        System.out.println("C2 消费者启动等待消费......");
        channel.basicConsume(QUEUE_NAME,true,deliverCallback,cancelCallback);
    }
}
